home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 2 / CD ACTUAL VOL 2.iso / docs / mini / caching- < prev    next >
Encoding:
Text File  |  1995-09-10  |  15.3 KB  |  425 lines

  1. Caching named mini howto.
  2.  
  3. Version 1
  4.  
  5. (C)opyright 1995 Nicolai Langfeldt.  Do not modify without amending
  6. copyright, distribute freely but retain copyright message.
  7.  
  8. Please send money, comments and/or questions to janl@ifi.uio.no.
  9.  
  10. I would appreciate it if someone sent me a section 3 for (c)slip
  11. users.
  12.  
  13. Contents:
  14. 1. Introduction
  15. 2. Setting it up
  16. 3. Automatic setup when connecting (and disconnecting).
  17. 4. Getting a new root.cache file.
  18. 5. Of forwarders and slaves.
  19.  
  20. 1. Introduction
  21.  
  22. This mini howto describes how to set up set up a caching name server.
  23. This is primarily usefull for people connected to the net with a
  24. (dialup) modem, using SLIP, PPP and similar protocols, because name
  25. lookups can be slow due to the slownes of modem comunications.
  26.  
  27. A clearification: When I say 'your machine' I mean the macine you dial
  28. up to the net from, for most people this is their home machine.  There
  29. is room for confusion because quite a few people dial up to their own
  30. internet connected machine at work, _that_ is not the machine I talk
  31. of in this howto, I talk about the machine you call up from, the one
  32. you connect to the net with a modem.
  33.  
  34. Before you start on this you should configure your machine so that you
  35. can telnet in and out of it, and make successfuly make all kinds of
  36. connections to the net, and you should be able to do 'telnet
  37. 127.0.0.1' and get your own machine. You also need good
  38. /etc/host.conf, /etc/resolve.conf and /etc/hosts files as a starting
  39. point.  If you don't already have all this set up and working the
  40. networking howto explains how to set it up.
  41.  
  42. I also assume you're not behind any kind of firewall that blocks name
  43. queries.  If you are you will need a special configuration that's
  44. mentioned in section 5.
  45.  
  46. Name serving on unix is done by a program called named.  This is a
  47. part of the bind package that's coordinated by Paul Vixie.  This can
  48. be gotten on Linux ftp sites, but chances are that you already have a
  49. named.  It's usualy called /usr/sbin/named.  You can use that if you
  50. already have it.
  51.  
  52. If you need to set up named for more than just caching, for example
  53. for setting up your own internet domain I sugest you get the book "DNS
  54. and BIND" by C. Liu and P. Albitz from O'Reilly & Associates,
  55. Sebastopol, CA, ISBN 0-937175-82-X 1992.  There are also docs in the
  56. bind distribution, including a FAQ and a manual as well as papers.
  57.  
  58. 2. Setting it up
  59.  
  60. Tip: Make backup copies of all the files I instruct you to change if
  61. you already have them, so if after going thru this nothing works you
  62. can get it back to your old, working state.
  63.  
  64. First you need a file called /etc/named.boot.  This is read when named
  65. starts.  For our purpose it should simply contain (remove leading
  66. spaces):
  67.  
  68.   ;  Boot file for nicolais caching name server
  69.   ;
  70.   directory /var/named
  71.   ;
  72.   ; type          domian                          source file or host
  73.   cache           .                               root.cache
  74.  
  75. A file named /var/named/root.cache is named in this.
  76. /var/named/root.cache should contain this (remove leading spaces
  77. again):
  78.  
  79.   ; ---- Root cache dump ----
  80.   .       IN      NS      NS.INTERNIC.NET.
  81.   .       IN      NS      AOS.ARL.ARMY.MIL.
  82.   .       IN      NS      NS1.ISI.EDU.
  83.   .       IN      NS      C.PSI.NET.
  84.   .       IN      NS      TERP.UMD.EDU.
  85.   .       IN      NS      NS.NASA.GOV.
  86.   .       IN      NS      NIC.NORDU.NET.
  87.   .       IN      NS      NS.ISC.ORG.
  88.   ;
  89.   ;  Prep the cache (hardwire the addresses).  Order does not matter
  90.   ;
  91.   NS.INTERNIC.NET.    999999    IN    A    198.41.0.4
  92.   AOS.ARL.ARMY.MIL.    999999    IN    A    128.63.4.82
  93.   AOS.ARL.ARMY.MIL.    999999    IN    A    192.5.25.82
  94.   NS1.ISI.EDU.        999999    IN    A    128.9.0.107
  95.   C.PSI.NET.        999999    IN    A    192.33.4.12
  96.   TERP.UMD.EDU.        999999    IN    A    128.8.10.90
  97.   NS.NASA.GOV.        999999    IN    A    128.102.16.10
  98.   NS.NASA.GOV.        999999    IN    A    192.52.195.10
  99.   NIC.NORDU.NET.    999999    IN    A    192.36.148.17
  100.   NS.ISC.ORG.        999999    IN    A    192.5.5.241
  101.  
  102. It describes the root name servers in the world.  This changes over
  103. time, see below for how to get updated data.
  104.  
  105. These two files are supposedly described in the named man page.  I say
  106. supposedly because that man page is probably one of the least clear
  107. man pages in creation if you don't already know how to set up named.
  108.  
  109. Next, when you're connected to the net you need a /etc/resolv.conf
  110. looking like this:
  111.  
  112.   search subdomain.your-domain.edu your-domain.edu
  113.   nameserver 127.0.0.1
  114.  
  115. The 'search' line specifies what domains should be searched for any
  116. hostnames want to connect to.  The 'nameserver' line specifies what
  117. address your machine can reach a nameserver at, in this case your own
  118. machine since that is where your named runs.
  119.  
  120. The example assumes you belong in the domain
  121. subdomain.your-domain.edu, your machine then, is probably called
  122. your-machine.subdomain.your-domain.edu.  The search line would
  123. normaly not contain your top domain ('edu' in this case).  If you
  124. frequently need to connect to hosts in another domain you can add that
  125. domain to the search line like this:
  126.  
  127.   search subdomain.your-domain.edu your-domain.edu other-domain.com
  128.  
  129. and so on. Obviosly you need to put real domain names in instead.
  130.  
  131. The last file you have to fix is /etc/host.conf.  There should be a
  132. line starting with 'order' and it should look like this:
  133.  
  134.   order hosts,bind
  135.  
  136. If there is no order line you should stick one in.  It tells the host
  137. name resolving routinges to first look in /etc/hosts, then ask the
  138. name server (which you in resolve.conf said is at 127.0.0.1)
  139.  
  140. These two latest files are documented in the resolv(8) manpage (do
  141. 'man 8 resolv').  That man page is IMHO readable, and everyone should
  142. read it.
  143.  
  144. Now you can connect to the world and test your setup.  Dial up and
  145. establish your connection the usual way.  Once the connection is
  146. established (and /etc/resolve.conf has the right 'nameserver' line)
  147. you start /usr/sbin/named.  If you look in your syslog message file
  148. (usualy called /var/adm/messages, use the command 'tail
  149. /var/adm/messages' to see it's end) after you start named you should
  150. see something like:
  151.  
  152.   Jan 14 23:13:14 roke named[671]: starting.  named 4.9.3-BETA9 Sat Jan 14 21:19:55 MET 1995    janl@roke:/usr/src/bind-4.9.3-BETA9/named
  153.   Jan 14 23:13:14 roke named[672]: Ready to answer queries. 
  154.  
  155. If there is any messages about errors then there is a mistake
  156. somewhere in the file named named in the message (one of named.boot
  157. and root.cache I hope :-) Kill named and go back and check the files.
  158.  
  159. Once named does not complain you can start querying it.  The program
  160. designed for this is nslookup. Start it by giving linux the command
  161. 'nslookup':
  162.  
  163.   $ nslookup
  164.   Default Server:  localhost
  165.   Address:  127.0.0.1
  166.  
  167.   > 
  168.  
  169. Now you can enter a query.  Try looking up some machine close to you.
  170. mnemosyne.uio.no is a Linux machine I run at the university of Oslo:
  171.  
  172.   > mnemosyne.uio.no
  173.   Server:  localhost
  174.   Address:  127.0.0.1
  175.  
  176.   Name:    mnemosyne.uio.no
  177.   Address:  129.240.21.233
  178.  
  179. nslookup now asked your named to look for the machine
  180. mnemosyne.uio.no.  It then contacted one of the name server machines
  181. named in your root.cache file, and asked it's way from there.  It
  182. might take some seconds before you get the result as it searches all
  183. the domains you named in /etc/resolve.conf.  If you try again you get
  184. this:
  185.  
  186.   > mnemosyne.uio.no
  187.   Server:  localhost
  188.   Address:  127.0.0.1
  189.  
  190.   Non-authoritative answer:
  191.   Name:    mnemosyne.uio.no
  192.   Address:  129.240.21.233
  193.  
  194. Note 'Non-authoritative answer:'.  That means that named did not go
  195. out on the network to ask this time, it instead looked in it's cache
  196. and found it there.  But the cached information _might_ be out of date
  197. (also called 'stale').  So you are informed of this by it saying
  198. 'Non-authorative answer:'.  So when nslookup says this the second time
  199. you ask for a host it's a sign it caches the information and the
  200. desired effect of setting up the named has been reached. You exit
  201. nslookup by giving the command 'exit'.
  202.  
  203. A warning: It is not smart to run named when you are not connected to
  204. the net, this is because named will try to send queries to the net and
  205. it has a long timeout, and you have to wait for this timeout every
  206. time some program tries to resolve a name.  The next section explains
  207. how I deal with seting up and taking down named when connecting and
  208. disconnecting to the net.
  209.  
  210. So now you know how to set up different configuration files so named
  211. works.
  212.  
  213. 3. Automatic setup when connecting (and disconnecting).
  214.  
  215. This section explains how I have set things up to automate everything.
  216. My way might not suit you at all, but you might get a idea from
  217. something I've done.  Also, I use ppp for dialup, while many use slip
  218. or cslip, so almost everything in your setup can be different from
  219. mine. But slip's dip program should be able to do many of the things I
  220. do.
  221.  
  222. Normaly, when I'm not connected to the net I have a resolv.conf file
  223. simply containing the line
  224.  
  225.   domain uio.no
  226.  
  227. This ensures I don't have to wait for the hostname resolving library
  228. to try to connect to a nameserver that can't help me.  But when I
  229. connect I want to start my named and have a resolv.conf looking like
  230. the one described above.  I have solved this by keeping two
  231. resolv.conf 'template' files named resolv.conf.local and
  232. resolve.conf.connected.  The latter looks like the resolve.conf
  233. described before in this document.
  234.  
  235. To automaticaly connect to the net I run a script called 'ppp-on':
  236.  
  237.   #!/bin/sh
  238.   cp -v /etc/resolv.conf.connected /etc/resolv.conf
  239.   echo calling...
  240.   pppd
  241.  
  242. pppd has a file called 'options' that tells it the particulars of how
  243. to get connected.  Once my ppp connection is up the pppd starts a
  244. script called ip-up (this is described in the pppd man page).  This is
  245. parts of the script:
  246.  
  247.   #!/bin/sh
  248.   ...
  249.   echo 1>&2 PPP: IP upp
  250.   ...
  251.   /usr/sbin/named
  252.   echo PPP: ip-up finished
  253.  
  254. I.e. I start my named there.  When ppp is disconnected pppd runs a
  255. script called ip-down:
  256.  
  257.   #!/bin/sh
  258.   echo 1>&2 PPP: IP down
  259.   cp /etc/resolv.conf.local /etc/resolv.conf
  260.   kill `cat /var/run/named.pid`
  261.  
  262. So this gets things configured and up when connecting and
  263. disconfigured and down when disconnecting.
  264.  
  265. 4. Getting a new root.cache file.
  266.  
  267. I mentioned that the root.cache information changes from time to time.
  268. So you might want to update it once in a long while.  Start nslookup thus:
  269.  
  270.   nslookup | tee nslookup.log
  271.  
  272. then nslookup the command
  273.  
  274.   > set type=ns
  275.  
  276. This means that nslookup should ask for 'ns' (or NameServer) records,
  277. it usualy asks for A, address records.
  278.  
  279.   > .
  280.  
  281. This means, get me root information.  In a unix filesystem the root
  282. is '/', in the name server system the root is '.' and is often written
  283. so.  The answer to my query was:
  284.  
  285.   Server:  localhost
  286.   Address:  127.0.0.1
  287.  
  288.   Non-authoritative answer:
  289.   (root)  nameserver = AOS.ARL.ARMY.MIL
  290.   (root)  nameserver = NS1.ISI.EDU
  291.   (root)  nameserver = C.PSI.NET
  292.   (root)  nameserver = TERP.UMD.EDU
  293.   (root)  nameserver = NS.NASA.GOV
  294.   (root)  nameserver = NIC.NORDU.NET
  295.   (root)  nameserver = NS.ISC.ORG
  296.   (root)  nameserver = NS.NIC.DDN.MIL
  297.   (root)  nameserver = NS.INTERNIC.NET
  298.  
  299.   Authoritative answers can be found from:
  300.   (root)  nameserver = AOS.ARL.ARMY.MIL
  301.   (root)  nameserver = NS1.ISI.EDU
  302.   (root)  nameserver = C.PSI.NET
  303.   (root)  nameserver = TERP.UMD.EDU
  304.   (root)  nameserver = NS.NASA.GOV
  305.   (root)  nameserver = NIC.NORDU.NET
  306.   (root)  nameserver = NS.ISC.ORG
  307.   (root)  nameserver = NS.NIC.DDN.MIL
  308.   (root)  nameserver = NS.INTERNIC.NET
  309.   AOS.ARL.ARMY.MIL        internet address = 128.63.4.82
  310.   AOS.ARL.ARMY.MIL        internet address = 192.5.25.82
  311.   NS1.ISI.EDU     internet address = 128.9.0.107
  312.   C.PSI.NET       internet address = 192.33.4.12
  313.   TERP.UMD.EDU    internet address = 128.8.10.90
  314.   NS.NASA.GOV     internet address = 128.102.16.10
  315.   NS.NASA.GOV     internet address = 192.52.195.10
  316.   NIC.NORDU.NET   internet address = 192.36.148.17
  317.   NS.ISC.ORG      internet address = 192.5.5.241
  318.   NS.NIC.DDN.MIL  internet address = 192.112.36.4
  319.  
  320. It says that the answer is non-authorative, and that an authorative
  321. answer can be gotten from one of a list of hosts.  We want a
  322. authorative answer so we tell nslookup to use one of the named
  323. servers.  I pick nic.nordu.net because nordunet is the Nordic research
  324. network and is thus close to me (I'm in Norway).  You can choose any
  325. you fancy, terp.umd.edu is probably good in USA.
  326.  
  327.   > server nic.nordu.net
  328.   Default Server:  NIC.NORDU.NET
  329.   Address:  192.36.148.17
  330.  
  331. Now to ask for the root ns records again:
  332.  
  333.   > .
  334.   Server:  NIC.NORDU.NET
  335.   Address:  192.36.148.17
  336.  
  337.   (root)  nameserver = TERP.UMD.EDU
  338.   (root)  nameserver = NS.NASA.GOV
  339.   (root)  nameserver = NIC.NORDU.NET
  340.   (root)  nameserver = NS.ISC.ORG
  341.   (root)  nameserver = NS.NIC.DDN.MIL
  342.   (root)  nameserver = NS.INTERNIC.NET
  343.   (root)  nameserver = AOS.ARL.ARMY.MIL
  344.   (root)  nameserver = NS1.ISI.EDU
  345.   (root)  nameserver = C.PSI.NET
  346.   (root)  nameserver = TERP.UMD.EDU
  347.   (root)  nameserver = NS.NASA.GOV
  348.   (root)  nameserver = NIC.NORDU.NET
  349.   (root)  nameserver = NS.ISC.ORG
  350.   (root)  nameserver = NS.NIC.DDN.MIL
  351.   (root)  nameserver = NS.INTERNIC.NET
  352.   (root)  nameserver = AOS.ARL.ARMY.MIL
  353.   (root)  nameserver = NS1.ISI.EDU
  354.   (root)  nameserver = C.PSI.NET
  355.   TERP.UMD.EDU    internet address = 128.8.10.90
  356.   NS.NASA.GOV     internet address = 128.102.16.10
  357.   NS.NASA.GOV     internet address = 192.52.195.10
  358.   NIC.NORDU.NET   internet address = 192.36.148.17
  359.   NS.ISC.ORG      internet address = 192.5.5.241
  360.   NS.NIC.DDN.MIL  internet address = 192.112.36.4
  361.   NS.INTERNIC.NET internet address = 198.41.0.4
  362.   AOS.ARL.ARMY.MIL        internet address = 192.5.25.82
  363.   AOS.ARL.ARMY.MIL        internet address = 128.63.4.82
  364.   NS1.ISI.EDU     internet address = 128.9.0.107
  365.  
  366. Mission acomplished, quit nslookup:
  367.  
  368.   > exit
  369.  
  370. You now have the complete nslookup seesion log in a file called
  371. nslookup.log.  Start a editor and remove all but the results of the
  372. last query.  To make a named.cache file of the rest you change it in
  373. this manner:
  374.  
  375.   (root)  nameserver = TERP.UMD.EDU
  376.  
  377. should become
  378.  
  379.   .    IN    NS    TERP.UMD.EDU.
  380.  
  381. Note the trailing '.'.  It specifies that edu is a root domain, and
  382. should be there.  Then you change lines on the form
  383.  
  384.   TERP.UMD.EDU    internet address = 128.8.10.90
  385.  
  386. to
  387.  
  388.   TERP.UMD.EDU.        999999    IN    A    128.8.10.90
  389.  
  390. Note the trailing . again.  Then save the file again.  If you examine
  391. the result of the edit and your /var/named/root.cache they should be
  392. remarkably alike, so this corresponds to the root.conf file.  Move the
  393. new file to /var/named/root.cache.  Now run /usr/sbin/named.restart
  394. and test your new setup by connecting to 
  395.  
  396. 5. Of forwarders and slaves.
  397.  
  398. There are one or two enhancements you can make on this setup.  One
  399. involves asking other close by name servers if they have the name
  400. cached, thus (possebly, if we're lucky) avoiding having to wait for a
  401. reply from halfway across the globe.  You can't use any close by
  402. nameserver for forwarding; it has to accept recursive queries (to
  403. quote the named manpage).  If you don't know any close-by forwarders
  404. ask your provider if they know any name servers you can use as
  405. forwarder.  In My Humble Opinion your provider should be be able to be
  406. one of your forwarders.  Never, ever use another server as forwarder
  407. without the permission of it's admin, it's rude.
  408.  
  409. A forwarders line should be in the named.boot file, and looks like
  410. this (DO NOT USE THIS LINE, IT WILL NOT WORK! Use your local
  411. forwarders instead):
  412.  
  413.   forwarders 127.0.0.2 127.0.0.3
  414.  
  415. You can list as many forwarders as you like.
  416.  
  417. A line like this
  418.  
  419.   slave
  420.  
  421. in named.boot will put your name server in slave mode, this means it
  422. will only query it's forwarders.  If you're behind a firewall or
  423. perhaps have to pay for traffic leaving your provider's net this is
  424. usefull.
  425.